//
//  MyImgVAlertView.m
//  NtoccShipper
//
//  Created by mac on 2020/1/17.
//  Copyright © 2020 zhuchongjin. All rights reserved.
//
#import "MyImgVAlertView.h"
#import "XLImageViewer.h"

static const CGFloat AlertViewWidth = 270.0;
//static const CGFloat AlertViewContentMargin = 9;
//static const CGFloat AlertViewVerticalElementSpace = 10;
//static const CGFloat AlertViewButtonHeight = 44;
//static const CGFloat AlertViewLineLayerWidth = 0.5;

@interface MyImgVAlertView()
@property (strong, nonatomic) CJImageView *imgVHeader;
//@property (strong, nonatomic) CJLabel *labTitle;
//@property (strong, nonatomic) CJLabel *labContent;
@property (strong, nonatomic) CJButton *btnSure;
@property (strong, nonatomic) CJButton *btnCancle;
@property (nonatomic,copy) OnSureClick sureBlock;
@property (nonatomic,copy) OnCancleClick cancleBlock;

@end

@implementation MyImgVAlertView


//-(instancetype)initWithTitle:(NSString *)strTitle strContent:(NSString *)strContent  ClickOnSure:(OnSureClick )sureClick ClickOnCancle:(OnCancleClick )cancleClick{
//
//    if (self = [super init]) {
//
//        self.frame = CGRectMake(0, 0, AlertViewWidth, 261);
//        self.backgroundColor = [UIColor cjWhiteColor];
//        [CJUtil getViewCutAllCornRound:self height:10];
//
//        strTitle =  [strTitle isEqualToString:@""] ? @"提示":strTitle;
//
//        [self addSubview:self.imgVHeader];
//        [self addSubview:self.labTitle];
//        [self addSubview:self.labContent];
//        [self addSubview:self.btnCancle];
//        [self addSubview:self.btnSure];
//
//        self.labTitle.text = strTitle;
//        self.labContent.text = strContent;
//        self.sureBlock = sureClick;
//        self.cancleBlock = cancleClick;
//
////        self.labContent.frame = [self adjustLabelFrameHeight:self.labContent];
//
//    }
//    return self;
//}


-(instancetype)initWithTitle:(NSString *)strTitle strImgV:(NSString *)imgName  ClickOnSure:(OnSureClick )sureClick ClickOnCancle:(OnCancleClick )cancleClick{
    
        if (self = [super init]) {
            
            self.frame = CGRectMake(0, 0, AlertViewWidth, 250);
            self.backgroundColor = [UIColor cjWhiteColor];
            [CJUtil getViewCutAllCornRound:self height:10];
            
//            strTitle =  [strTitle isEqualToString:@""] ? @"提示":strTitle;
            
            [self addSubview:self.imgVHeader];
//            [self addSubview:self.labTitle];
//            [self addSubview:self.labContent];
            [self addSubview:self.btnCancle];
            [self addSubview:self.btnSure];
            [self.imgVHeader sd_setImageWithURL:[NSURL URLWithString:imgName] placeholderImage:[UIImage imageNamed:@"zcj_xiangji"]];
            
//            self.labTitle.text = strTitle;
            self.sureBlock = sureClick;
            self.cancleBlock = cancleClick;

    //        self.labContent.frame = [self adjustLabelFrameHeight:self.labContent];
            @weakify(self);
            [self.imgVHeader setTapActionWithBlock:^{
                @strongify(self);
                [[XLImageViewer shareInstanse] showNetImages:@[imgName] index:0 fromImageContainer:self.imgVHeader];
            }];
            
        }
        return self;
}



- (void)btnClickSureAction:(CJButton *)sender{
    if (self.sureBlock) {
        
        self.sureBlock(@"");
    }
    WLAlertView * alerView =(WLAlertView *)[self superview];
    [alerView dismissAnimated:YES];
}
- (void)btnClickCancleAction:(CJButton *)sender{
    if (self.cancleBlock) {
        
        self.cancleBlock(@"");
    }
    WLAlertView * alerView =(WLAlertView *)[self superview];
    [alerView dismissAnimated:YES];
}



#pragma mark ----------lazy

- (CJImageView *)imgVHeader{
    if (!_imgVHeader) {  // 173  118
        _imgVHeader = CJImageView.imgInit
        .imgVFrame(CGRectMake((self.width - 173)/2, 30, 173, 118))
        .imgVImageName(@"zcj_xiangji")
        ;
    }
    return _imgVHeader;
}

//- (CJLabel *)labTitle{
//    if (!_labTitle) {
//        _labTitle = CJLabel.labInit
//        .labFrame(CGRectMake(0, _imgVHeader.bottom + 10, self.width, 20))
//        .labFontSize(18)
//        .labAlignment(NSTextAlignmentCenter)
//        ;
//    }
//    return _labTitle;
//}

//- (CJLabel *)labContent{
//    if (!_labContent) {
//
//        _labContent = CJLabel.labInit
//        .labFrame(CGRectMake(10, _labTitle.bottom + 10, self.width-20, 50))
//        .labFontSize(16)
//        .labAlignment(NSTextAlignmentCenter)
//        .labTextColor([UIColor cjSubheadTextColor])
//        .labAdjustsFontSizeToFitWidth(YES)
//        ;
//    }
//    return _labContent;
//}
- (CJButton *)btnCancle{
    
    if (!_btnCancle) {
        _btnCancle = CJButton.btnInit
        .btnFrame(CGRectMake(45, _imgVHeader.bottom + 30, 80,35))
        .btnText(@"取消")
        .btnFontSize(15)
        .btnBgColor([UIColor cjWhiteColor])
        .btnCornerWidth(0.5)
        .btnCornerRadius(5)
        .btnCornerColor([UIColor cjMainColor])
        .btnNormalTitleColor([UIColor cjMainColor])
        .btnTargetAction(self,@selector(btnClickCancleAction:))

        ;
    }
    return _btnCancle;
}

- (CJButton *)btnSure{
    
    if (!_btnSure) {
        _btnSure = CJButton.btnInit
        .btnFrame(CGRectMake(self.width -45 - 80, _btnCancle.top, _btnCancle.width,_btnCancle.height ))
        .btnText(@"确定")
        .btnFontSize(15)
        .btnBgColor([UIColor cjMainColor])
//        .btnCornerWidth(0.5)
        .btnCornerRadius(5)
        .btnNormalTitleColor([UIColor cjWhiteColor])
        .btnTargetAction(self,@selector(btnClickSureAction:))
        ;
    }
    return _btnSure;
}
@end


